package middol.upload

import groovy.transform.CompileStatic
import groovy.util.logging.Slf4j
import middol.global.BusinessException
import middol.result.Result
import org.springframework.stereotype.Component

/**
* @Description:    上传文件上下文
* @Author:         zhangjiayu@middol.com
* @CreateDate:     2020/10/22 9:44
* @Version:        1.0
*/
@Slf4j
@Component
@CompileStatic
class UploadHandlerContext {
    private IUploadHandler iUploadHandler

    void setiUploadHandler(IUploadHandler iUploadHandler) {
        this.iUploadHandler = iUploadHandler
    }
/**
     * 上传文件
     * @param iFileInfo
     */
    List<Result> handleUpload(IFileInfo iFileInfo){
        if(iUploadHandler){
            iUploadHandler.handleUpload(iFileInfo)
        }else{
            log.error("iUploadHandler is null, please check iUploadHandler service")
            throw new BusinessException("iUploadHandler is null, please check iUploadHandler service")
        }
    }
}
